import App from './App'
import Vue from 'vue'
import store from './store'
import md5 from 'static/js/md5.js'
Vue.config.productionTip = false
Vue.prototype.$store = store
App.mpType = 'app'
const app = new Vue({
	store,
	...App
})
app.$mount(); 
Vue.prototype.ip = 'http://hy.xxfzg.com/api/';
Vue.prototype.upload = 'http://hy.xxfzg.com/cms/';
Vue.prototype.url = 'http://hy.xxfzg.com';
Vue.prototype.md5 = (data) => {
	return md5(data + 'csadaddsxczc'); 
} 
Vue.prototype.GetJson = (url, md, data, su, err) => {
	uni.request({
		url: url,
		data: data, 
		method: md,
		dataType: 'json',
		header: {
			'content-type': 'application/x-www-form-urlencoded'
		},
		success(e) {
			if (su != null) su(e.data)
		},
		fail(err) {
			if (!err) err(e)
		}
	})
}
Vue.prototype.ustime = (time)=>{
	var timestamp2 = new Date();
	var timestamp = Date.parse(timestamp2) / 1000
	
	let cz = timestamp - time;
	var crtTime = new Date(time * 1000);
	if(cz < 60){
		return '刚刚'
	}else if(cz < 3600){
		return parseInt(cz / 60) + '分钟前';
	}else if (cz < 86400 && crtTime.getDate() == timestamp2.getDate()){
		return getApp().gettime('hh:mm',crtTime);
	}else if(timestamp2.getDate() - crtTime.getDate() == 1){
		return '昨天 '
	}else if(cz < 31536000){
		return getApp().gettime('MM-dd',crtTime);
	}else{
		return getApp().gettime('yyyy-MM-dd hh:mm',crtTime);
	}
}
Vue.prototype.gettime = (date,fmt)=>{
	if (fmt == null) fmt = 'yyyy-MM-dd hh:mm:ss';
	let daa = new Date(Number(date) * 1000);
	var o = {
		"M+" : daa.getMonth()+1,     //月份 
		"d+" : daa.getDate(),     //日 
		"h+" : daa.getHours(),     //小时 
		"m+" : daa.getMinutes(),     //分 
		"s+" : daa.getSeconds(),     //秒 
		"q+" : Math.floor((daa.getMonth()+3)/3), //季度 
		"S" : daa.getMilliseconds()    //毫秒 
	}; 
	if(/(y+)/.test(fmt))
	fmt=fmt.replace(RegExp.$1, (daa.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	for(var k in o)
	if(new RegExp("("+ k +")").test(fmt)) 
	fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 
	return fmt; 
}
Vue.prototype.showToast = (title)=>{
	//return uni.showToast({icon:'none',title});
	return uni.showToast({
		title: title,
		icon: 'none',
		position: 'bottom',
		duration: 300
	})
}
Vue.prototype.showload = (title)=>{
	return uni.showLoading({title});
}
Vue.prototype.hideload = ()=>{
	return uni.hideLoading()
}
Vue.prototype.isdata = (e) =>{
	let is = false;
	switch (e.code){
		case 200:
			is = true;
			break;
		case 1:
			is = true;
			break;
		case 404:
			uni.showToast({icon:'none',title:'数据异常'})
			break;	
		case 405:
			uni.showToast({icon:'none',title:'登录数据失效，请重新登录'})
			break;
		case 601:
			uni.showToast({icon:'none',title:'余额不足'});
			break;
		case 700:
			uni.showToast({icon:'none',title:'支付失败！'});
			break;
		default:
			break;
	}
	return is;
}
Vue.prototype.countSubstr = (str, substr, isIgnore)=>{//取字符串出现的次数
	return str.split(substr).length - 1;
}

Vue.prototype.getphone = (phone)=>{
	return phone.substr(0,3) + '****' + phone.substr(7,4);
}
Vue.prototype.showtime = (time) => {
	var nowtime = new Date(); //获取当前时间
	if(time > nowtime.getTime()){
		var lefttime = time - nowtime.getTime(), //距离结束时间的毫秒数
			leftd = Math.floor(lefttime / (1000 * 60 * 60 * 24)), //计算天数
			lefth = Math.floor(lefttime / (1000 * 60 * 60) % 24), //计算小时数
			leftm = Math.floor(lefttime / (1000 * 60) % 60), //计算分钟数
			lefts = Math.floor(lefttime / 1000 % 60); //计算秒数
		var arr = [];
		if(leftd > 0)arr.push(leftd + "天");
		if(lefth > 0)arr.push(lefth);
		if(leftm > 0)arr.push(leftm);
		arr.push(lefts );
		return arr.join(':');
	}else{
		return false;
	}
	
	
}